package com.carleasoft.mps.forum.business.answer.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.carleasoft.mps.core.result.R;
import com.carleasoft.mps.forum.business.answer.bean.ForumFollow;
import com.carleasoft.mps.forum.business.answer.bean.po.ForumUserPo;
import com.carleasoft.mps.forum.business.answer.bean.vo.ForumFollowVo;
import com.carleasoft.mps.forum.business.answer.service.ForumFollowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zang
 * @since 2023-05-09
 */
@RestController
@RequestMapping("/forumFollow")
public class ForumFollowController {

    @Autowired
    private ForumFollowService forumFollowService;


    /**
     * @author zang
     * @desc 添加关注
     * @date 2023-05-19
     */
    @PostMapping("/addForumFollow")
    public R addForumFollow(@RequestBody ForumFollow forumFollow) {
        Boolean flag = forumFollowService.addForumFollow(forumFollow);
        if(flag){
            return R.ok();
        } else {
            return R.failed("0000001","已关注改用户");
        }
    }
    
    /**
     * @author zang
     * @desc 取消关注
     * @date 2023-06-19
     */
    @PostMapping("/delForumFollow")
    public R delForumFollow(@RequestBody ForumFollow forumFollow) {
        forumFollowService.delForumFollow(forumFollow);
        return R.ok();
    }

    
    /**
     * @author zang
     * @desc 分页查询关注信息
     * @date 2023-06-19
     */
    @PostMapping("/pageForumFollow")
    public R pageForumFollow(@RequestBody ForumUserPo forumUserPo) {
        Page page = new Page(forumUserPo.getCurrent(), forumUserPo.getSize());
        Page<ForumFollowVo> res = forumFollowService.pageForumFollow(page,forumUserPo);
        return R.ok(res);
    }



}

